package com.jeomo.common.quartz.starter.listener;

import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * <h3>springboot-quartz</h3>
 * <p>监听定时任务</p>
 *
 * @author : 崔贺
 * @date : 2020-08-18 10:34
 **/
public class LogJobListener implements JobListener {

    private static Logger log = LoggerFactory.getLogger(LogJobListener.class);

    @Override
    public String getName() {
        return "MyJobListener";
    }

    /**
     * * (1)
     * 任务执行之前执行
     */
    @Override
    public void jobToBeExecuted(JobExecutionContext context) {
        JobDetail jobDetail = context.getJobDetail();
        log.debug("**JobListener**执行之前*** ：" + jobDetail.getKey().getName());
    }

    /**
     * (2)
     * 这个方法正常情况下不执行,但是如果当TriggerListener中的vetoJobExecution方法返回true时,那么执行这个方法.
     * 需要注意的是 如果方法(2)执行 那么(1),(3)这个俩个方法不会执行,因为任务被终止了嘛.
     */
    @Override
    public void jobExecutionVetoed(JobExecutionContext context) {

    }

    /**
     * * (3)
     * 任务完毕执行
     */
    @Override
    public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) {
        JobDetail jobDetail = context.getJobDetail();
        log.debug("*JobListener***执行完毕*** ：" + jobDetail.getKey().getName());
    }
}
